<template>
    <div>
        <el-table :data="goodlist" border style="width: 100%">
            <el-table-column prop="id" label="商品编号">
            </el-table-column>
            <el-table-column prop="goodsname" label="商品名称">
            </el-table-column>
            <el-table-column prop="price" label="商品价格">
            </el-table-column>
            <el-table-column prop="market_price" label="市场价格">
            </el-table-column>

            <el-table-column prop="address" label="图片" width="120">
                <template slot-scope="item">
                    <div>
                        <img :src="item.row.img" alt="" class="img">
                    </div>
                </template>
            </el-table-column>
            <el-table-column prop="address" label="是否新品" width="80">
                <template slot-scope="item">
                    <div>
                        <el-tag v-if="item.row.isnew == 1" type="success" plain size="medium">是</el-tag>
                        <el-tag v-else type="danger" plain size="medium">否</el-tag>
                    </div>
                </template>
            </el-table-column>
            <el-table-column prop="address" label="是否热卖" width="80">
                <template slot-scope="item">
                    <div>
                        <el-tag v-if="item.row.ishot" type="success" plain size="medium">是</el-tag>
                        <el-tag v-else type="danger" plain size="medium">否</el-tag>
                    </div>
                </template>
            </el-table-column>
            <el-table-column prop="address" label="状态" width="80">
                <template slot-scope="item">
                    <div>
                        <el-tag v-if="item.row.status == 1" type="success" plain size="medium ">启用</el-tag>
                        <el-tag v-else type="danger" plain size="medium ">禁用</el-tag>
                    </div>
                </template>
            </el-table-column>
            <el-table-column prop="address" label="操作">
                <template slot-scope="item">
                    <div>
                        <el-button type="primary" size="mini" @click="edit(item.row.id)">编辑</el-button>
                        <el-button type="danger" size="mini" @click="del(item.row.id)">删除</el-button>
                    </div>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination background layout="prev, pager, next" :page-size="size" :total="count" @current-change="change">
        </el-pagination>
    </div>
</template>
<script>
import { goodsdelete } from "../../request/api"
import { mapGetters, mapActions } from 'vuex';
export default {
    data() {
        return {

        }
    },
    methods: {
        ...mapActions({
            getGoods: "manage/getGoodsInfoActions",
            getCount: "manage/getCountAction",
            changePageInfo: "manage/changePageAction",
        }),
        del(id) {
            // console.log(id);
            this.$confirm('此操作不可逆, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                //   点击删除删除数据
                goodsdelete({ id }).then(res => {
                    // console.log(res);
                    if (res.code == 200) {
                        this.$message(res.msg);
                        this.getCount()
                        this.getGoods()
                    }
                })

                this.$message({
                    type: 'success',
                    message: '删除成功!'
                });
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });
            });

        },
        edit(id) {
            this.$emit("edit", id)

        },
        change(e) {
            // console.log(e);
            this.changePageInfo(e)
            this.getGoods()
        }



    },
    mounted() {
        this.getGoods()
        this.getCount()


    },
    watch: {},
    computed: {
        ...mapGetters({
            goodlist: "manage/getGoods",
            size: "manage/getSize",
            count: "manage/getCount",
        })
    },
    filters: {},
    components: {}
}
</script>
<style scoped>
.img {
    width: 100px;
    height: 100px;
}
</style>